﻿using Foundation.Core;
using Microsoft.AspNetCore.Mvc;

namespace Dyao.Book.Web.Extensions
{
    public abstract class ValidateBusinessException : BusinessException
    {
        public ValidateBusinessException() : base("validate.error")
        {

        }

        public ValidateBusinessException(string errorCode)
            : base(errorCode)
        {
            ErrorCode = errorCode;
        }

        public ValidateBusinessException(string errorCode, string message)
            : base(errorCode, message)
        {
            ErrorCode = errorCode;
        }

        public abstract ApiResult CreateApiResult();
    }

    public class ValidationProblemDetailsBusinessException : ValidateBusinessException
    {
        public ValidationProblemDetails ProblemDetails { get; }

        public ValidationProblemDetailsBusinessException(ValidationProblemDetails problemDetails)
        {
            ProblemDetails = problemDetails;
        }

        public override ApiResult CreateApiResult()
        {
            return ProblemDetails;
        }

        public override string ToString()
        {
            return ProblemDetails.Errors.Values.JoinAsString(";");
        }

    }
}
